package cn.net.xyan.easy.spring.core.config.value;

import cn.net.xyan.easy.spring.core.utils.JsonHelper;
import com.fasterxml.jackson.databind.JavaType;

/**
 * Created by xiashenpin on 16/1/17.
 */
public class ConfigKey implements Comparable<ConfigKey> {
    String key;
    String describe;

    JavaType valueType;

    Object defaultValue;

    public ConfigKey(String key, String describe, JavaType valueType, Object defaultValue) {
        this.key = key;
        this.describe = describe;
        this.valueType = valueType;
        this.defaultValue = defaultValue;
    }

    public ConfigKey(String key, String describe, Class<?> valueCls, Object defaultValue) {
        this.key = key;
        this.describe = describe;
        this.valueType = JsonHelper.javaType(valueCls);
        this.defaultValue = defaultValue;
    }

    public String getKey() {
        return key;
    }

    protected void setKey(String key) {
        this.key = key;
    }

    public String getDescribe() {
        return describe;
    }

    protected void setDescribe(String describe) {
        this.describe = describe;
    }

    public JavaType getValueType() {
        return valueType;
    }

    protected void setValueType(JavaType valueType) {
        this.valueType = valueType;
    }

    public Object getDefaultValue() {
        return defaultValue;
    }

    protected void setDefaultValue(Object defaultValue) {
        this.defaultValue = defaultValue;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ConfigKey configKey = (ConfigKey) o;

        return key.equals(configKey.key);

    }

    @Override
    public int hashCode() {
        return key.hashCode();
    }


    @Override
    public int compareTo(ConfigKey o) {
        return this.key.compareTo(o.key);
    }
}
